<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
  <title>天量科技管理后台</title>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width">
  <link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
  <link rel="stylesheet" href="css/templatemo_main.css">
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body ng-app="app" ng-controller="index">
  <div class="navbar navbar-inverse" role="navigation">
      <div class="navbar-header">
        <div class="logo"><h1>天量科技管理后台</h1></div>
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button> 
      </div>   
    </div>
    <div class="template-page-wrapper">
      <div class="navbar-collapse collapse templatemo-sidebar">
        <ul class="templatemo-sidebar-menu">
          <li>
            <form class="navbar-form">
              欢迎您:{{user.name || '访客'}}</span>
            </form>
          </li>

          <li ng-repeat="menu in menus" ng-class="menu.menuclass">
            <a ng-click="redi(menu.url)" ng-if="menu.items.length==0"><i ng-class="menu.icon"></i>{{menu.label}}</a>
            <a href="#" ng-if="menu.items.length>0"  ng-click="menuclick(menu)">
              <i ng-class="menu.icon"></i> {{menu.label}} <div class="pull-right"><span class="caret"></span></div>
            </a>
            <ul class="templatemo-submenu" ng-if="menu.items.length>0">
              <li ng-repeat="item in menu.items" ng-click="redi(item.url)"><a href="javascript:void(0)">{{item.label}}</a></li>
            </ul>
          </li>
          <li>
            <a href="#" data-toggle="modal" data-target="#confirmModal"><i class="fa fa-sign-out"></i>退出登录</a>
          </li>
        </ul>
      </div><!--/.navbar-collapse -->

      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb">
            <li><a ng-click="redi('index.html')">首页</a></li>
            <li ng-if="user.tel==null"><a ng-click="fShowLogin()">登录</a></li>
            <li ng-if="user.tel==null"><a ng-click="fShowReg()">注册</a></li>
            <li ng-if="user.tel!=null"><a ng-click="redi('account.html')" href="javascript:void(0)">个人信息修改</a></li>
            <li ng-if="user.tel!=null"><a href="#" data-toggle="modal" data-target="#confirmModal">退出</a></li>
          </ol>

          <div class="row" ng-if="haserror">
            <div class="alert alert-danger alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
              <strong>发生异常情况:{{errormessage}}</strong>
            </div>
          </div>

          <div class="row" ng-if="showLogin && !haserror">
            <div class="alert alert-warning alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
              <strong>你尚未登录，当前身份是游客，请先登录</strong>
            </div>
            <div class="col-md-12">
              <form role="form" id="templatemo-preferences-form-login">
                <div class="row" >
                  <div class="col-md-6 margin-bottom-15">
                    <label for="login_tel" class="control-label">手机号</label>
                    <input type="number" class="form-control" id="login_tel" placeholder="17700000000" ng-model="$parent.login_tel">
                  </div>

                  <div class="col-md-6 margin-bottom-15">
                    <label for="login_password">密码</label>
                    <input type="password" class="form-control" id="login_password" placeholder="New Password" ng-model="$parent.login_password">
                  </div>

                  <div class="col-md-12">
                    <span class="btn btn-warning"><a ng-click="login()">登录</a></span>
                  </div>
                </div>
              </form>
            </div>
          </div>

          <div class="row" ng-if="showReg" id="regdiv">
            <div class="alert alert-info alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
              <strong>如果没有帐号，你就先注册</strong>
            </div>
            <div class="col-md-12">
              <form role="form" id="templatemo-preferences-form-reg">
                <div class="row" >
                  <div class="col-md-6 margin-bottom-15">
                    <label for="reg_tel" class="control-label">手机号</label>
                    <input type="number"  id="reg_tel" placeholder="17600000000" ng-model="$parent.reg_tel">
                    <button type="submit" class="btn btn-info" ng-show="btn_code_show" ng-click="sendCode()">发送验证码</button>
                    <span ng-show="!btn_code_show">请输入你收到的验证码</span>
                    <input type="number"  id="reg_code" ng-show="!btn_code_show" ng-model="$parent.reg_code">
                  </div>

                  <div class="col-md-6 margin-bottom-15" ng-show="!btn_code_show">
                    <label for="reg_name" class="control-label">名称</label>
                    <input type="text" class="form-control" id="reg_name" value="John" ng-model="$parent.reg_name">
                    <label for="reg_password">请输入密码</label>
                    <input type="password" class="form-control" id="reg_password" placeholder="New Password" ng-model="$parent.reg_password">
                    <label for="reg_password_2">请再次输入密码</label>
                    <input type="password" class="form-control" id="reg_password_2" placeholder="New Password" ng-model="$parent.reg_password_2">
                  </div>

                  <div class="col-md-12">
                    <button type="submit" class="btn btn-info" ng-show="!btn_code_show" ng-click="reg()">注册</button>
                  </div>
                </div>
              </form>
            </div>
          </div>

          <div class="row" ng-if="showInfo">
            <div class="alert alert-success alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
              {{user.name}}已登录,IP地址为{{systeminfo.remote_ip}}
            </div>
          </div>
        </div>
      </div>

      <!-- Modal -->
      <div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
              <h4 class="modal-title" id="myModalLabel">确定退出吗</h4>
            </div>
            <div class="modal-footer">
              <a ng-click="logout()" class="btn btn-primary" data-dismiss="modal">确定</a>
              <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
          </div>
        </div>
      </div>

      <footer class="templatemo-footer">
        <div class="templatemo-copyright">
          <p>Copyright &copy; 2018 By <a href="http://skyquant.cn" title="天量科技" target="_blank">天量科技</a></p>
        </div>
      </footer>
    </div>
</body>

<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/angular.js/1.5.8/angular.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="js/common.js"></script>
<script src="js/templatemo_script.js"></script>
<script type="text/javascript">
  'use strict';
  var app = angular.module('app', []);
  app.controller('index', ['$scope', '$http','$location', '$filter','$window','$timeout',function ($scope, $http,$location,$filter,$window,$timeout) {

      //每个页面都要有的方法
      $scope.init = function(){
        getUser($http,$scope,'首页',null);
      }

      $scope.logout = function(){
        logout($http);
      }

      $scope.menuclick=function(menu){
        changemenuclass($scope,menu);
      }

      $scope.redi=function(url){
          location.href = url;
      }

      //每个页面都需要重写此方法，发生在init之后
      $scope.initAfter = function(){
        if($scope.user!=null && $scope.user.tel!=null){
          $scope.showLogin = false;
          $scope.showReg = false;
          $scope.showInfo = true;
        }else{
          $scope.showLogin = true;
          $scope.showReg = false;
          $scope.showInfo = false;
        }
      }

      $scope.fShowLogin = function(){
        $scope.haserror = false;
        $scope.errormessage = "";
        $scope.login_password = "";
        if($scope.user!=null && $scope.user.tel!=null){
          $scope.showLogin = false;
          $scope.showReg = false;
          $scope.showInfo = true;
        }else{
          $scope.showLogin = true;
          $scope.showReg = false;
          $scope.showInfo = false;
        }
      }

      $scope.fShowReg = function(){
        $scope.haserror = false;
        $scope.errormessage = "";
        $scope.reg_tel = "";
        if($scope.user!=null && $scope.user.tel!=null){
          $scope.showLogin = false;
          $scope.showReg = false;
          $scope.showInfo = true;
        }else{
          $scope.showLogin = false;
          $scope.showReg = true;
          $scope.showInfo = false;
          $scope.btn_code_show=true;//验证码按钮
        }
      }

      $scope.login = function(){
        var pData = {tel:$scope.login_tel,password:$scope.login_password};
        $http({method:'POST',url:'quant4j-service/authority/login',params:pData}).success(function(data,header,config,status) {
          if(data.ok){
            alert('登录成功');
            $scope.init();
          }else{
            $scope.haserror = true;
            $scope.errormessage = data.message;
          }
        }).error(function(data,header,config,status){
          $scope.haserror = true;
          $scope.errormessage = data.message;
        });
      }

      $scope.sendCode = function(){
        var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        if (!phoneReg.test($scope.reg_tel)) {
            alert('请输入有效的手机号码！');
            return false;
        }
        var pData = {tel:$scope.reg_tel};
        $http({method:'POST',url:'quant4j-service/authority/send_reg_sms',params:pData}).success(function(data,header,config,status) {
          if(data.ok){
            alert('短信输入成功，请输入验证码，同时补全其他信息');
            $scope.btn_code_show = false;
          }else{
            alert(data.message);
          }
        }).error(function(data,header,config,status){
            console.log(data);
        });
      }

      $scope.reg = function(){
        if($scope.reg_password != $scope.reg_password_2){
          alert("请确认两次密码输入相同");
          return;
        }
        if($scope.reg_password==null || $scope.reg_password==""){
          alert("密码不能为空");
          return;
        }
        var pData = {tel:$scope.reg_tel,name:$scope.reg_name,code:$scope.reg_code,password:$scope.reg_password};
        $http({method:'POST',url:'quant4j-service/authority/reg',params:pData}).success(function(data,header,config,status) {
          if(data.ok){
            alert("注册成功,请点击登录链接进行登录");
            $scope.btn_code_show = true;
          }else{
            alert(data.message);
          }
        }).error(function(data,header,config,status){
            console.log(data);
        });
      }

      $scope.init();
      $scope.showLogin = false;//显示登录面板
      $scope.showReg = false;//显示注册面板
      $scope.showInfo = false;//显示信息面板
      $scope.btn_code_show=true;//验证码按钮
  }]);
</script>
</html>